`
https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/
`

/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  const n = prices.length
  // dp[第 i 天][持有/不持有股票]
  const dp = Array.from({ length: n }, () => new Array(2).fill(0))

  for (let i = 0; i < n; i++) {
    // 处理边界
    if (i - 1 === -1) {
      dp[i][0] = 0
      dp[i][1] = -prices[i]
      continue
    }
    // 休息或卖掉
    dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i])
    // 休息或买入
    dp[i][1] = Math.max(dp[i - 1][1], dp[i - 1][0] - prices[i])
  }

  return dp[n - 1][0]
};